package cn.e2win.biz.zdzx;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import cn.e2win.biz.comm.ViewExcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.e2win.base.controller.MyException;
import cn.e2win.base.json.vo.Result;
import cn.e2win.biz.base.BaseController;
import cn.e2win.biz.base.BaseService;
import cn.e2win.biz.base.CommonController;
import cn.e2win.biz.base.CommonService;
import cn.e2win.biz.dbo.CyzjEmp;
import cn.e2win.biz.dbo.ZdzxEmp;
import org.springframework.web.servlet.ModelAndView;


@Controller
@Scope("request")
@RequestMapping("/zdzx")
public class ZdzxController extends BaseController {

	@Autowired
	private CommonController commonController;
	
	@Autowired
	private ZdzxService zdzxService;
	@Autowired
	private CommonService commonService;
	
	@Override
	public BaseService initService() {
		return zdzxService;
	}
	

	@RequestMapping("toZdzxEmpEditor/{id}")
	public String toZdzxEmpEditor(HttpServletRequest request, @PathVariable(ID) Integer id, ModelMap modelMap){
		Map<String, Object> obj = zdzxService.getEntity(new ZdzxEmp(id));
		obj.put("orgName", "武汉市中小企业职业教育指导中心");
		modelMap.put(OBJECT, obj);
		return "zdzx/zdzxEmpEditor";
	}

	@RequestMapping("editZdzxEmp")
	@ResponseBody
	public Result editCyzjEmp(HttpServletRequest request,@ModelAttribute ZdzxEmp obj,ModelMap modelMap) throws MyException{
		Result r = new Result();
		zdzxService.editZdzxEmp(obj);
		r.setCallbackType(Result.CLOSE_CURRENT);
		r.setNavTabId("listView_"+modelMap.get(FUNID));
		return r;
	}


	@RequestMapping("zdzxEmpPager")
	public String zdzxEmpPager(HttpServletRequest request, ModelMap modelMap){
		if("approve".equals(todo)){
			pager.getScMap().put("approveStatus", "SUBMITED");
		}else if("submit".equals(todo)){
			pager.getScMap().put("approveStatus_IN", "'UNSUBMIT','REJECTED'");
		}
		zdzxService.pagerZdzxEmp(pager);
		modelMap.put("pager", pager);
		return "zdzx/zdzxEmpPager";
	}

	@RequestMapping("zdzxEmpPagerExcel")
	public ModelAndView customerPagerExcel(HttpServletRequest request, ModelMap modelMap) {
		pager.setReturnAll(true);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("key",zdzxEmpPager(request,modelMap));
		model.put("list", pager.getResultList());
		return new ModelAndView(new ViewExcel(), model);
	}
	
}
